
import cn.hutool.json.JSONUtil;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.*;

public class B {

    public static void main(String[] args) throws ParseException {

        Map<Integer, List<String>> map = new HashMap<>();

        List<String> value = new ArrayList<>();
        value.add("a");
        value.add("b");
        value.add("c");
        map.put(1, value);
        List<String> strings = map.get(1);
        strings.add("d");
        System.out.println("map" + JSONUtil.toJsonStr(map));

    }

    private static void method5() {
        DateTime dateTime1 = DateTime.now().withYear(2018).withMonthOfYear(9);
        System.out.println(dateTime1.dayOfMonth().getMaximumValue());
        List<String> strings = new ArrayList<>();
        strings.add("a");
        strings.add("b");
        strings.add("c");
        String join = StringUtils.join(strings, ",");
        System.out.println("join = " + join);
        String join1 = String.join(",", strings);
        System.out.println("join1 = " + join1);
        String collect1 = strings.stream().collect(joining(","));
        System.out.println("collect1 = " + collect1);
/*
        int[] arr = {8, 8, 8, 7, 5, 5, 4, 4, 3, 2};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                for (int k = 0; k < arr.length; k++) {
                    for (int l = 0; l < arr.length; l++) {
                        for (int m = 0; m < arr.length; m++) {
                            for (int n = 0; n < arr.length; n++) {
                                for (int o = 0; o < arr.length; o++) {
                                    for (int p = 0; p < arr.length; p++) {
                                        for (int q = 0; q < arr.length; q++) {
                                            for (int r = 0; r < arr.length; r++) {
                                                String result = "1";
                                                String concat = result.concat(arr[i] + "").
                                                        concat(arr[j] + "").
                                                        concat(arr[k] + "").
                                                        concat(arr[l] + "").
                                                        concat(arr[m] + "").
                                                        concat(arr[n] + "").
                                                        concat(arr[o] + "").
                                                        concat(arr[p] + "").
                                                        concat(arr[q] + "").
                                                        concat(arr[r] + "");
                                                System.out.println("result = " + concat);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }*/

        DateTime dateTime = DateTime.now().withDayOfMonth(3);
        System.out.println(dateTime.plusDays(1));
        System.out.println("dateTime = " + dateTime);
        for (int i = 3; i <= 15; i++) {
            System.out.println("i = " + i);
        }
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        List<D> collect = list.stream().map(D::new).collect(toList());
        System.out.println("collect = " + collect);
    }

    private void method3() {
        System.out.println(DateTime.now().getDayOfMonth());
        List<String> dateList = new ArrayList<>();
        dateList.add("2019-10-01");
        dateList.add("2019-10-09");
        dateList.add("2019-10-07");
        dateList.add("2019-10-14");
        dateList.add("2019-10-21");
        dateList.add("2019-10-03");
        dateList.add("2019-10-30");
        System.out.println("dateList = " + dateList);
        dateList.sort(String::compareTo);
        System.out.println("dateList sort = " + dateList);
    }

    private static void method2() throws ParseException {
        System.out.println(DateTime.now().getDayOfMonth());
        String date = "2019-10";
        DateTime dateTime = new DateTime(date + "-01");
        String s = dateTime.toString("yyyy-MM-dd");
        System.out.println("s = " + s);
        System.out.println(dateTime.dayOfMonth().withMaximumValue().toString("yyyy-MM-dd"));


        System.out.println(judgeSelectType(date));

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        Integer reduce = list.stream().reduce(0, Integer::sum);
        System.out.println("reduce = " + reduce);

        String str1 = "2019-10-1";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = dateFormat.parse(str1);
        System.out.println(dateFormat.format(parse));
    }

    private static int judgeSelectType(String date) {
        DateTime now = DateTime.now();
        DateTime paramDate = new DateTime(date + "-1");
        if (now.getYear() == paramDate.getYear() && now.getMonthOfYear() == paramDate.getMonthOfYear()) {
            // 同年同月 查看当前月数据,需要从历史表查出当前日之前的历史数据和当前日以及以后的实时数据
            // 如当前是2019-10-24 如果查看的是 2019-10的数据,则需要从历史表查出2019-10-24之前的历史数据和2019-10-24及2019-10-31的所有数据
            // 然后两个结果做合并
            return 0;
        } else {
            // 不是同年同月 判断和当前月1号的前后关系. 如果是当前月1号之前的,查历史数据, 否则查实时数据
            DateTime currentMonthFirstDay = now.withDayOfMonth(1);
            if (currentMonthFirstDay.isAfter(paramDate)) {
                return -1;
            }
        }
        return 1;
    }

    private static void dateBewteenAnd() {
        DateTime startDateTime = new DateTime("2019-08-01");
        DateTime endDateTime = new DateTime("2019-10-24");
        Interval i = new Interval(startDateTime, endDateTime);
        boolean contained = i.contains(new DateTime("2019-10-24"));
        System.out.println("contained = " + contained);
    }

    private static void method1() throws ParseException {
    /*Calendar c = Calendar.getInstance();
    c.set(2000, 2, 0); //输入类型为int类型
    System.out.println(c.get(Calendar.DAY_OF_MONTH));*/

        String str1 = "2019-10-01";
        String str2 = "2019-10-1";

        String s1 = "2019-10-25";
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(Objects.equals(format.parse(str1), format.parse(str2)));
        System.out.println("-----------------------");
        Date parse = format.parse(s1);
        System.out.println(parse);
        Date now = new Date();
        System.out.println(now.after(parse));

        System.out.println(format.parse("2019-10-1"));

        List<Integer> l1 = new ArrayList<>();
        l1.add(2);
        l1.add(5);
        l1.add(1);
        l1.add(9);
        l1.add(7);
        l1.sort(Comparator.comparingInt(Integer::intValue));
        System.out.println(l1);

        List<String> strings = processAdvertiseScheduleTableTitle("2000-03");
        System.out.println("strings = " + strings);
        for (int i = 1; i < strings.size(); i++) {
            System.out.println(i);
        }


        List<List<String>> partition = ListUtils.partition(strings, 10);
        System.out.println("partition = " + partition);
    }

    private static List<String> processAdvertiseScheduleTableTitle(String date) {
        List<String> result = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        String[] dateArr = date.split("-");
        int year = Integer.parseInt(dateArr[0]);
        int month = Integer.parseInt(dateArr[1]);
        calendar.set(year, month, 0);
        // 第一个字段是月份
        result.add(String.valueOf(month));
        result.addAll(IntStream.rangeClosed(1, calendar.get(Calendar.DAY_OF_MONTH)).mapToObj(String::valueOf).collect(toList()));
        return result;
    }
}
